﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace VideoSpliter.CustomControl
{
    public class RegexTextbox:TextBox
    {
        public static readonly DependencyProperty ValidRegexProperty = DependencyProperty.Register(
            "ValidRegex", typeof(string), typeof(RegexTextbox), new PropertyMetadata("*.*"));

        public string ValidRegex
        {
            get { return (string) GetValue(ValidRegexProperty); }
            set { SetValue(ValidRegexProperty, value); }
        }

        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            var text = Text + e.Text;
            e.Handled = !Regex.IsMatch(text, ValidRegex);
            base.OnPreviewTextInput(e);
        }
    }
}
